const mysql = require('mysql2/promise');

async function testDatabase() {
  const pool = mysql.createPool({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'movie_recommendation',
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
  });

  try {
    // 测试连接
    const connection = await pool.getConnection();
    console.log('数据库连接成功');

    // 检查数据库
    const [databases] = await connection.query('SHOW DATABASES');
    console.log('可用数据库:', databases.map(db => db.Database));

    // 检查表
    const [tables] = await connection.query('SHOW TABLES');
    console.log('数据库中的表:', tables);

    // 检查 movies 表结构
    const [movieColumns] = await connection.query('DESCRIBE movies');
    console.log('movies 表结构:', movieColumns);

    // 检查 movies 表数据
    const [movieCount] = await connection.query('SELECT COUNT(*) as count FROM movies');
    console.log('movies 表中的记录数:', movieCount[0].count);

    connection.release();
  } catch (error) {
    console.error('数据库测试失败:', error);
  } finally {
    await pool.end();
  }
}

testDatabase(); 